home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0228_Re: Rotating Text.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  2.0 KB  |  52 lines

  1.  
  2. Try the following function.  I don't remember where I got it from, but it
  3. works well!  The only thing to remember here is the parameter 'd' is in
  4. tenths of a degree.  So, if you want to rotate the text 45 degrees, 'd'
  5. should be 450.  Sorry for the funny wrapping, I'm sure you can figure it
  6. out:
  7.  
  8. procedure CanvasTextOutAngle(c: TCanvas; x,y: Integer; d: Word; s: string);
  9. var
  10.   LogRec: TLOGFONT;     {* Storage area for font information *}
  11.   OldFontHandle,        {* The old font handle *}
  12.   NewFontHandle: HFONT; {* Temporary font handle *}
  13. begin
  14.   if Application.Terminated then Exit;
  15.   {* Get the current font information. We only want to modify the angle *}
  16.   GetObject(c.Font.Handle, SizeOf(LogRec), Addr(LogRec));
  17.   {* Modify the angle. "The angle, in tenths of a degrees, between the base
  18.      line of a character and the x-axis." (Windows API Help file.)*}
  19.   LogRec.lfEscapement := d;
  20.   {* Create a new font handle using the modified old font handle *}
  21.   NewFontHandle := CreateFontIndirect(LogRec);
  22.   {* Save the old font handle! We have to put it back when we are done! *}
  23.   OldFontHandle := SelectObject(c.Handle,NewFontHandle);
  24.   {* Finally. Output the text! *}
  25.   c.Brush.Style := bsClear;
  26.   c.TextOut(x,y,s);
  27.   {* Put the font back the way we found it! *}
  28.   NewFontHandle := SelectObject(c.Handle,OldFontHandle);
  29.   {* Delete the temporary (NewFontHandle) that we created *}
  30.   DeleteObject(NewFontHandle);
  31. end; {* CanvasTextOutAngle *}
  32.  
  33. --
  34. David S. Becker
  35. ADP Dealer Services (Plaza R&D)
  36. dsb@plaza.ds.adp.com
  37. (503)402-3236
  38.  
  39. Stephen Gould <sgould@extro.ucc.su.OZ.AU> wrote in article
  40. <59tup1$1i9@metro.ucc.su.OZ.AU>...
  41. > Hi,
  42. > Does anyone know of a good way to rotate text and display it in a 
  43. > PaintBox. At the moment I am creating a TCanvas object in memory, drawing
  44.  
  45. > the text on it, then rotating the whole canvas and dumping it in the 
  46. > paintbox. Is there a better way? The text comes out looking pretty bad.
  47. > Steve.
  48. > gouldy@mad.scientist.com
  49. >
  50. >